package org.example.events.hostable.harassment;

import org.example.models.abstracts.AbstractLiving;
import org.example.models.interfaces.Action;
import org.example.models.interfaces.own.Ownable;
import org.example.person.Person;

import java.util.List;


public class HostHarassmentActions {
    public static Action<Person> hostHarassment(HarassmentEvent event, AbstractLiving victim) {
        return (Person person) -> {
            if(event.isStarted()) return;

            List<Ownable> personOwnables = person.getOwnables();
            if (personOwnables.contains(event)) return;

            personOwnables.add(event);
            event.setStarted(true);
            event.setVictim(victim);
        };
    }

    public static Action<Person> processParticipants(HarassmentEvent event) {
        return person -> {
            List<Ownable> personOwnables = person.getOwnables();
            if(!personOwnables.contains(event)) return;

            boolean success;
            do {
                success = event.processParticipant();
            } while (success);
        };
    }

    public static Action<Person> stopHarassment(HarassmentEvent event) {
        return (Person person) -> {
            List<Ownable> personOwnables = person.getOwnables();
            if(!personOwnables.contains(event)) return;
            event.setStarted(false);
            personOwnables.remove(event);
        };
    }
}
